package com.imooc;

import com.imooc.bean.Person;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

/**
 * @Date:2021/10/8/21:52
 * @Description:
 */
public class CollectionTest {

    @Test
    public void test01(){
        Collection list = new ArrayList(); //有序

        list.add(123);
        list.add(456);
        list.add(new String("Tom"));
        list.add(new Person("Tee",18));

        boolean contains = list.contains(123);
        System.out.println("contains = " + contains);

        System.out.println(list.contains(new String("Tom"))); //true
        System.out.println(list.contains(new Person("Tee",18)));  //false ==》想要变为true，需要重写 equals

        List<Integer> lsit2 = Arrays.asList(123, 456);
        System.out.println(list.containsAll(lsit2));


    }

    @Test
    public void test02(){
        Collection list = new ArrayList();
        list.add(123);
        list.add(456);
        System.out.println(list);
        list.remove(123);
        System.out.println("list = " + list);


    }

    @Test
    public void test03(){
        Collection list1 = new ArrayList();
        list1.add(123);
        list1.add(456);


        Collection list2 = new ArrayList();
        list2.add(23);
        list2.add(456);
        boolean b = list1.retainAll(list2);
        System.out.println(b);
        System.out.println(list1); //求交集，并将交集给list1

    }

    @Test
    public void test04(){
        Collection list1 = new ArrayList();
        list1.add(123);
        list1.add(456);
        list1.add(new String("Tom"));
        list1.add(new Person("Tee",18));

        Object[] objects = list1.toArray();
        for (int i = 0; i < objects.length; i++) {
//            System.out.println(objects[i]);
        }

        int[] ints = {123, 456};
        System.out.println(ints);

    }


    @Test
    public void test05(){
        ArrayList list1 = new ArrayList();
        list1.add(123);
        list1.add(456);
        list1.add(new String("Tom"));
        list1.add(new Person("Tee",18));

        int i = list1.indexOf(123);
        list1.set(0, 1234);
        
        System.out.println("i = " +list1);


    }
}
